package com.erpx.api.trade;

import com.erpx.api.WdtClient;
import com.erpx.api.param.PlatformOrderCreateParam;
import com.erpx.utils.JsonUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.erpx.api.CommonConstants;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PlatformTradeCreateService {

    /**
     * 创建原始订单
     * @throws Exception
     */
    public static void tradePush() throws Exception {
        WdtClient client = new WdtClient(CommonConstants.sid, CommonConstants.appkey, CommonConstants.appSecret, CommonConstants.baseUrl);

        Map<String, String> params = new HashMap<String, String>();
        List<PlatformOrderCreateParam> list = new ArrayList<>();
        String str = "[{\"tid\":\"CHS00003\",\"trade_status\":30,\"pay_status\":2,\"delivery_term\":1,\"buyer_nick\":\"\\u6da6\\u4e07\\u5bb6\\u751f\\u9c9c\\u8d85\\u5e02\\u914d\\u9001\\u5230\\u5bb6\",\"receiver_name\":\"\\u6da6\\u4e07\\u5bb6\\u751f\\u9c9c\\u8d85\\u5e02\\u914d\\u9001\\u5230\\u5bb6\",\"receiver_province\":\"北京\",\"receiver_city\":\"北京\",\"receiver_district\":\"朝阳区\",\"receiver_address\":\"\\u65b0\\u677e\\u8302\\u6a3e\\u5c71\\u4e00\\u671f\\u4e94\\u53f7\\u697c\\u6da6\\u4e07\\u5bb6\\u751f\\u9c9c\\u8d85\\u5e02\\u914d\\u9001\\u5230\\u5bb6\\u914d\\u9001\\u5230\\u5bb6\",\"receiver_mobile\":\"13199473669\",\"post_amount\":0,\"cod_amount\":0,\"ext_cod_fee\":0,\"other_amount\":0,\"paid\":37,\"order_list\":[{\"oid\":\"CHS00002-1\",\"num\":5,\"price\":37,\"status\":30,\"refund_status\":0,\"goods_id\":823,\"spec_id\":971,\"goods_no\":\"G8274165871413132743\",\"spec_no\":971,\"goods_name\":\"\\u3010\\u98df\\u841d\\u7c7d\\u3011\\u5c0f\\u56db\\u6839\\u4fc4\\u5f0f\\u4f20\\u7edf\\u7ea2\\u80a0160\\u514b*9\\u888b\",\"spec_name\":\"160\\u514b*9\\u888b(7)\",\"adjust_amount\":0,\"discount\":0,\"share_discount\":0},{\"oid\":\"CHS00002-2\",\"num\":2,\"price\":37,\"status\":30,\"refund_status\":0,\"goods_id\":823,\"spec_id\":971,\"goods_no\":\"G8274165871413132743\",\"spec_no\":971,\"goods_name\":\"\\u3010\\u98df\\u841d\\u7c7d\\u3011\\u5c0f\\u56db\\u6839\\u4fc4\\u5f0f\\u4f20\\u7edf\\u7ea2\\u80a0160\\u514b*9\\u888b\",\"spec_name\":\"160\\u514b*9\\u888b(7)\",\"adjust_amount\":0,\"discount\":0,\"share_discount\":0}]}]";
        //list = JsonUtils.deserialize(str,new TypeReference<>() {});

        params.put("trade_list", JsonUtils.serialize(list));
        params.put("shop_id","10");
        try {
            String response = client.execute("trade_push.php", params);
            System.out.println(response);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
